import datetime
import math
import os
import os.path
import random
import re
import threading

import pandas as pd
from openpyxl import load_workbook
from pubsub import pub

from 文档自动填写GUI程序.common import split_string_by_multiple_delimiters

'''
充盈系数默认填写灌注记录
'''


class PerfusionThread(threading.Thread):
    def __init__(self, path, piler_no, interval=12, speed=40):
        super().__init__()
        self.path = path
        self.piler_no = piler_no
        self.speed = speed
        self.interval = interval

    def run(self):
        try:
            # 灌注数据填写
            self.get_data()
            # 灌注时间与拆管数据填写
            self.set_time()
        except Exception as e:
            print(e.with_traceback())
            pub.sendMessage('error_status', message=e)

    def get_data(self):
        path = self.path
        no = self.piler_no
        delimiters = [',', ';', '，', '；', '\n']
        piler_no_list = split_string_by_multiple_delimiters(no, delimiters)
        template = "./钻孔桩水下混凝土浇注施工记录模板.xlsx"
        df = pd.read_excel(path, sheet_name="灌注记录")
        for piler_no in piler_no_list:
            flag = 0
            piler_no = re.sub(r"\s+", "", piler_no)
            if piler_no is None or piler_no == "":
                return
            for index, row in df.iterrows():
                if str(row["桩号"]).lower() == piler_no.lower():
                    if pd.isna(row["护筒顶高度"]):
                        pub.sendMessage('info_status', message='桩基数据错误，请检查该桩号' + row["桩号"] + "的数据")
                    else:
                        if pd.notna(row["第一车"]):
                            write_excel(template, row)
                        else:
                            pub.sendMessage('info_status',
                                            message='该桩号' + piler_no + "没有灌注数据，请填写完成再生成!")
                    flag = 1
            if flag == 0:
                pub.sendMessage('info_status', message='该桩号' + piler_no + "数据不存在!")

    def set_time(self):
        path = self.path
        no = self.piler_no
        speed = self.speed
        interval = self.interval
        print(interval)
        delimiters = [',', ';', '，', '；', '\n']
        piler_no_list = split_string_by_multiple_delimiters(no, delimiters)
        df = pd.read_excel(path, sheet_name="灌注记录")
        for piler_no in piler_no_list:
            flag = 0
            piler_no = re.sub(r"\s+", "", piler_no)
            if piler_no is None or piler_no == "":
                return
            for index, row in df.iterrows():
                if str(row["桩号"]).lower() == piler_no.lower():
                    if pd.isna(row["护筒顶高度"]):
                        pub.sendMessage('info_status', message='桩基数据错误，请检查该桩号' + row["桩号"] + "的数据")
                    else:
                        if pd.notna(row["第一车"]):
                            handle(row, speed, interval)
                        else:
                            pub.sendMessage('info_status',
                                            message='该桩号' + piler_no + "没有灌注数据，请填写完成再生成!")
                    flag = 1
            if flag == 0:
                pub.sendMessage('info_status', message='该桩号' + piler_no + "数据不存在!")


def write_excel(path, data):
    L22 = 0
    L23 = 0
    L24 = 0
    piler_no = data["桩号"]
    wb = load_workbook(path)
    sheet = wb.active
    sheet["C9"] = data["墩台编号"]
    sheet["K9"] = data["桩号"]
    Q9 = data["桩径"]
    sheet["Q9"] = Q9
    sheet["T9"] = data["设计桩底标高"]
    sheet["K12"] = data["护筒顶高度"]

    设计桩长 = data["设计桩长"]
    sheet["E14"] = "=PI()*Q9*Q9/4*(" + str(设计桩长) + "+0.5" + ")"
    h = data["灌注前孔底标高"]
    sheet["E12"] = h

    K12 = data["护筒顶高度"]
    E12 = h
    s = round((data["护筒顶高度"] - h) % 1, 1)
    if s == 0.1:
        sheet["F20"] = round(K12 - (E12 + 0.4), 2)
    elif s == 0.2:
        sheet["F20"] = round(K12 - (E12 + 0.5), 2)
    else:
        sheet["F20"] = round(K12 - (E12 + 0.3), 2)
    sheet["S14"] = data["坍落度"]
    # 浇筑量
    L20 = data["第一车"]
    sheet["L20"] = L20

    L21 = data["第二车"]
    sheet["L21"] = L21

    if pd.isna(data["第三车"]):
        sheet["D22"] = data["第三车"]
        sheet["F22"] = data["第三车"]
        sheet["H22"] = data["第三车"]
        sheet["J22"] = data["第三车"]
        sheet["O22"] = data["第三车"]
        sheet["R22"] = data["第三车"]
    else:
        L22 = data["第三车"]
        sheet["L22"] = L22

    理论超灌量 = data["理论超灌量"]

    if pd.isna(data["第四车"]):
        sheet["D23"] = data["第四车"]
        sheet["F23"] = data["第四车"]
        sheet["H23"] = data["第四车"]
        sheet["J23"] = data["第四车"]
        sheet["O23"] = data["第四车"]
        sheet["R23"] = data["第四车"]

        if 理论超灌量 >= 2:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.2))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.1)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.1)
            sheet["D22"] = round(D22, 2)

        elif 1.5 < 理论超灌量 < 2:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.1))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.05)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.1)
            sheet["D22"] = round(D22, 2)
        elif 0.8 < 理论超灌量 <= 1.5:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.05))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.05)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.05)
            sheet["D22"] = round(D22, 2)
        else:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.03))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D22"] = round(D22, 2)

    else:
        L23 = data["第四车"]
        sheet["L23"] = L23

    if pd.isna(data["第五车"]):
        sheet["D24"] = data["第五车"]
        sheet["F24"] = data["第五车"]
        sheet["H24"] = data["第五车"]
        sheet["J24"] = data["第五车"]
        sheet["O24"] = data["第五车"]
        sheet["R24"] = data["第五车"]
        if pd.notna(data["第四车"]):
            if 理论超灌量 >= 2:
                D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.15))
                sheet["D20"] = round(D20, 2)
                D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.15)
                sheet["D21"] = round(D21, 2)
                D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.15)
                sheet["D22"] = round(D22, 2)
                D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.15)
                sheet["D23"] = round(D23, 2)
            elif 1.5 < 理论超灌量 < 2:
                D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.1))
                sheet["D20"] = round(D20, 2)
                D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.1)
                sheet["D21"] = round(D21, 2)
                D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.1)
                sheet["D22"] = round(D22, 2)
                D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.1)
                sheet["D23"] = round(D23, 2)
            elif 0.8 < 理论超灌量 <= 1.5:
                D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.05))
                sheet["D20"] = round(D20, 2)
                D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.05)
                sheet["D21"] = round(D21, 2)
                D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.05)
                sheet["D22"] = round(D22, 2)
                D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.05)
                sheet["D23"] = round(D23, 2)
            else:
                D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.01))
                sheet["D20"] = round(D20, 2)
                D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.03)
                sheet["D21"] = round(D21, 2)
                D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.03)
                sheet["D22"] = round(D22, 2)
                D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.03)
                sheet["D23"] = round(D23, 2)
    else:
        L24 = data["第五车"]
        sheet["L24"] = L24
        if 理论超灌量 >= 2:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.1))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.15)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.1)
            sheet["D22"] = round(D22, 2)
            D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.11)
            sheet["D23"] = round(D23, 2)
            D24 = D23 - L24 / (math.pi * Q9 * Q9 / 4 * 1.15)
            sheet["D24"] = round(D24, 2)
        elif 1.5 < 理论超灌量 < 2:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.05))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.1)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.1)
            sheet["D22"] = round(D22, 2)
            D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.05)
            sheet["D23"] = round(D23, 2)
            D24 = D23 - L24 / (math.pi * Q9 * Q9 / 4 * 1.1)
            sheet["D24"] = round(D24, 2)
        elif 0.8 < 理论超灌量 <= 1.5:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.03))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D22"] = round(D22, 2)
            D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D23"] = round(D23, 2)
            D24 = D23 - L24 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D24"] = round(D24, 2)
        else:
            D20 = (K12 - E12) - (L20 / (math.pi * Q9 * Q9 / 4 * 1.01))
            sheet["D20"] = round(D20, 2)
            D21 = D20 - L21 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D21"] = round(D21, 2)
            D22 = D21 - L22 / (math.pi * Q9 * Q9 / 4 * 1.01)
            sheet["D22"] = round(D22, 2)
            D23 = D22 - L23 / (math.pi * Q9 * Q9 / 4 * 1.01)
            sheet["D23"] = round(D23, 2)
            D24 = D23 - L24 / (math.pi * Q9 * Q9 / 4 * 1.03)
            sheet["D24"] = round(D24, 2)
    file_name = piler_no + ".钻孔桩水下混凝土浇注施工记录.xlsx"
    pub.sendMessage('info_status', message=file_name + '    ----->文件生成完毕')
    full_path = os.path.join("./out", file_name)
    wb.close()
    wb.save(full_path)


# 处理拆管数据填写
def handle_pipes(sheet):
    fristH = sheet["F20"].value
    sheet["F21"] = fristH
    for i in range(0, 4):
        index = str(i + 21)
        # 混凝土液面高度
        dH = sheet["D" + index].value
        fH = fristH
        if fH % 1 > 0.5:
            remainder = math.ceil(fH) % 3
        else:
            remainder = math.floor(fH) % 3
        if dH is not None:
            if remainder == 0:
                delta = fH - dH
                if delta >= 8:
                    sheet["H" + index] = 2
                    sheet["J" + index] = 6
                    fristH -= 6
                    if sheet["L" + str(i + 1 + 21)].value is not None:
                        sheet["F" + str(i + 1 + 21)] = fristH
                    else:
                        num = math.ceil(sheet["F" + index].value) // 3
                        sheet["H" + index] = int(num)
                        sheet["J" + index] = int(num) * 3
                elif 5 <= delta < 8:
                    sheet["H" + index] = 1
                    sheet["J" + index] = 3
                    fristH -= 3
                    if sheet["L" + str(i + 1 + 21)].value is not None:
                        sheet["F" + str(i + 1 + 21)] = fristH
                    else:
                        num = math.ceil(sheet["F" + index].value) // 3
                        sheet["H" + index] = int(num)
                        sheet["J" + index] = int(num) * 3

                else:
                    if sheet["H" + str(i + 21 + 1)].value is None:
                        if math.ceil(fristH) <= 3:
                            sheet["H" + index] = 1
                            sheet["J" + index] = 3
                        elif 3 < math.ceil(fristH) <= 6:
                            sheet["H" + index] = 2
                            sheet["J" + index] = 6
                        else:
                            num = sheet["F" + index].value // 3
                            sheet["H" + index] = int(num)
                            sheet["J" + index] = int(num) * 3
                    else:
                        sheet["H" + index] = 0
                        sheet["J" + index] = 0
            elif remainder == 2 or remainder == 1:
                delta = fH - dH
                if delta >= 4 and i == 0:
                    if remainder == 2:
                        sheet["H" + index] = 1
                        sheet["J" + index] = 2
                        fristH -= 2
                        if sheet["L" + str(i + 1 + 21)].value is not None:
                            sheet["F" + str(i + 1 + 21)] = fristH
                    elif remainder == 1:
                        sheet["H" + index] = 1
                        sheet["J" + index] = 1
                        fristH -= 1
                        if sheet["L" + str(i + 1 + 21)].value is not None:
                            sheet["F" + str(i + 1 + 21)] = fristH


# 处理灌注时间填写
def handle_time(sheet, start_time, piler_no, speed=40, interval=12):
    time_obj = datetime.datetime.strptime(str(start_time), "%Y-%m-%d %H:%M:%S")
    new_time = time_obj
    for i in range(0, 5):
        index = str(20 + i)
        height = sheet["L" + index].value
        length = sheet["H" + index].value
        if pd.notna(height):
            start = new_time.strftime("%m-%d %H:%M")
            time_temp = math.ceil(height / speed * 60)
            delta = datetime.timedelta(minutes=time_temp)
            end = new_time + delta
            new_time = end
            print(interval)
            if length != 0 and length is not None:
                delta = datetime.timedelta(minutes=random.randint(interval - 4, interval))
            else:
                delta = datetime.timedelta(minutes=random.randint(1, 2))
            new_time += delta
            time_str = start + " ~ " + end.strftime("%m-%d %H:%M")
            sheet["A" + index] = time_str
    pub.sendMessage('info_status', message="该桩 " + piler_no + " 结束时间：" + str(new_time))


# 重新设置公式
def set_formula(sheet, row):
    sheet["S12"] = "=T9+0.1"

    sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1))"
    sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1)"
    sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.03)"

    h = sheet["E12"].value
    s = round((sheet["K12"].value - h) % 1, 1)
    if s == 0.1:
        sheet["F20"] = "=K12-(E12+0.4)"
    elif s == 0.2:
        sheet["F20"] = "=K12-(E12+0.5)"
    else:
        sheet["F20"] = "=K12-(E12+0.3)"
    sheet["F21"] = "=F20"
    sheet["F22"] = "=F21-J21"

    sheet["O20"] = "=L20"
    sheet["O21"] = "=O20+L21"
    sheet["O22"] = "=O21+L22"

    理论超灌量 = row["理论超灌量"]
    # 第四车
    if sheet["L23"].value is not None:
        sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.03)"
        sheet["F23"] = "=F22-J22"
        sheet["O23"] = "=O22+L23"
    else:
        if 理论超灌量 >= 2:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.2))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.1)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.1)"

        elif 1.5 < 理论超灌量 < 2:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.1))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.05)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.1)"
        elif 0.8 < 理论超灌量 <= 1.5:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.05))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.05)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.05)"
        else:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.03))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.03)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.03)"
    # 第五车
    if sheet["L24"].value is not None:
        sheet["D24"] = "=D23-L24/(PI()*$Q$9*$Q$9/4*1.01)"
        sheet["F24"] = "=F23-J23"
        sheet["O24"] = "=O23+L24"

        if 理论超灌量 >= 2:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.1))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.15)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.1)"
            sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.11)"
            sheet["D24"] = "=D23-L24/(PI()*$Q$9*$Q$9/4*1.15)"
        elif 1.5 < 理论超灌量 < 2:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.05))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.1)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.1)"
            sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.05)"
            sheet["D24"] = "=D23-L24/(PI()*$Q$9*$Q$9/4*1.1)"
        elif 0.8 < 理论超灌量 <= 1.5:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.03))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.03)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.03)"
            sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.03)"
            sheet["D24"] = "=D23-L24/(PI()*$Q$9*$Q$9/4*1.03)"
        else:
            sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.01))"
            sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.03)"
            sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.01)"
            sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.01)"
            sheet["D24"] = "=D23-L24/(PI()*$Q$9*$Q$9/4*1.03)"
    else:
        if sheet["L23"].value is not None:
            if 理论超灌量 >= 2:
                sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.15))"
                sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.15)"
                sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.15)"
                sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.15)"

            elif 1.5 < 理论超灌量 < 2:
                sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.1))"
                sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.1)"
                sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.1)"
                sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.1)"
            elif 0.8 < 理论超灌量 <= 1.5:
                sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.05))"
                sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.05)"
                sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.05)"
                sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.05)"
            else:
                sheet["D20"] = "=(K12-E12)-(L20/(PI()*$Q$9*$Q$9/4*1.01))"
                sheet["D21"] = "=D20-L21/(PI()*$Q$9*$Q$9/4*1.03)"
                sheet["D22"] = "=D21-L22/(PI()*$Q$9*$Q$9/4*1.03)"
                sheet["D23"] = "=D22-L23/(PI()*$Q$9*$Q$9/4*1.03)"


# 时间处理
def handle(row, speed, interval):
    start_time = row["灌注时间"]
    piler_no = row["桩号"]
    file_name = str(piler_no) + ".钻孔桩水下混凝土浇注施工记录.xlsx"
    path = os.path.join("./out", file_name)
    if os.path.exists(path):
        wb = load_workbook(path, data_only=True)
        sheet = wb.active
        设计桩长 = row["设计桩长"]
        sheet["E14"] = "=PI()*Q9*Q9/4*(" + str(设计桩长) + "+0.5" + ")"
        if sheet["D24"].value is not None:
            min_height = round(sheet["D24"].value, 2)
        elif sheet["D23"].value is not None:
            min_height = round(sheet["D23"].value, 2)
        elif sheet["D22"].value is not None:
            min_height = round(sheet["D22"].value, 2)
        else:
            min_height = round(sheet["D21"].value, 2)
        if pd.notna(row["筒顶与设计桩顶标高之差"]):
            if min_height > row["筒顶与设计桩顶标高之差"]:
                pub.sendMessage('info_status', message=piler_no + "桩的灌注充盈系数有问题，需要调整充盈系数")
            if abs(row["筒顶与设计桩顶标高之差"] - min_height) > 2:
                pub.sendMessage('info_status', message=piler_no + "桩的灌注充盈系数取值不太合适，请调整取值")
        # 拆管程序
        handle_pipes(sheet)
        # 处理灌注时间
        handle_time(sheet, start_time, piler_no, speed, interval)
        set_formula(sheet, row)
        pub.sendMessage('info_status', message=file_name + '    ----->桩基灌注时间填写完毕')
        wb.close()
        wb.save(path)
    else:
        pub.sendMessage('info_status', message="文件" + path + ",不存在")
